package com.yootk.lombok;

import lombok.Cleanup;
import lombok.Data;
import lombok.NonNull;
import lombok.SneakyThrows;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

@Data
public class MessageRead {
    @NonNull
    private String filePath;    // 文件路径
    @NonNull
    private String fileName;    // 文件名称

    @SneakyThrows
    public String load() {
        // 自动关闭
        @Cleanup InputStream input = new FileInputStream(new File(this.filePath, this.fileName));
        byte[] data = new byte[1024];
        int len = input.read(data);
        return new String(data, 0, len);
    }
}
